<script setup lang="ts">
import {ref,onMounted} from 'vue'
import type { UserInfo } from '@/types/user';
import { getUserInfo } from '@/api/user';
import { showFailToast } from 'vant'
// 定义用户信息变量
let user = ref<UserInfo>()
onMounted(async ()=>{
    await getUserInfo().then(
        res => {
            user.value = res.data
        }
    ).catch(err =>{
        showFailToast(err.message) //
    }) 
})
// 准备快捷工具模块数据
const tools = [
  { label: '我的问诊', path: '/user/consult',imgSrc:'user-tool-01' },
  { label: '我的处方', path: '/' ,imgSrc:'user-tool-02'},
  { label: '家庭档案', path: '/user/patient',imgSrc:'user-tool-03' },
  { label: '地址管理', path: '/user/address' ,imgSrc:'user-tool-04'},
  { label: '我的评价', path: '/', imgSrc:'user-tool-05' },
  { label: '官方客服', path: '/' ,imgSrc:'user-tool-06'},
  { label: '设置', path: '/set' ,imgSrc:'user-tool-07'}
]

</script>

<template>
  <div class="user-page">
    <div class="user-page-head">
      <div class="top">
        <van-image
          round
          fit="cover"
          :src="user?.avatar"
        />
        <div class="name">
          <p>{{ user?.account }}</p>
          <p><van-icon name="edit" /></p>
        </div>
      </div>
      <van-row>
        <van-col span="6">
          <p>{{ user?.collectionNumber }}</p>
          <p>收藏</p>
        </van-col>
        <van-col span="6">
          <p>{{ user?.likeNumber }}</p>
          <p>关注</p>
        </van-col>
        <van-col span="6">
          <p>{{ user?.score }}</p>
          <p>积分</p>
        </van-col>
        <van-col span="6">
          <p>{{  user?.couponNumber}}</p>
          <p>优惠券</p>
        </van-col>
      </van-row>
    </div>
    <div class="user-page-order">
      <div class="head">
        <h3>药品订单</h3>
        <router-link to="/order">全部订单 <van-icon name="arrow" /></router-link>
      </div>
      <van-row>
        <van-col span="6">
          <cp-icon href="user-paid" />
          <p>待付款</p>
        </van-col>
        <van-col span="6">
          <cp-icon href="user-shipped" />
          <p>待发货</p>
        </van-col>
        <van-col span="6">
          <cp-icon href="user-received" />
          <p>待收货</p>
        </van-col>
        <van-col span="6">
          <cp-icon href="user-finished" />
          <p>已完成</p>
        </van-col>
      </van-row>
    </div>
    <div class="user-page-group">
      <h3>快捷工具</h3>
      <van-row>
        <van-col span="6" v-for="(item,i) in tools" :key="i" >
          <van-cell :to="item.path">
            <cp-icon :href="item.imgSrc" />
          <p>{{ item.label }}</p>
          </van-cell>
      </van-col>
      </van-row>
    </div>
  </div>
  
</template>

<style lang="scss" scoped>
.user-page {
  background-color: var(--cp-bg);
  min-height: calc(100vh - 50px);
  padding: 0 15px 65px;
  // 头部
  &-head {
    height: 200px;
    background: linear-gradient(180deg, rgba(44, 181, 165, 0.46), rgba(44, 181, 165, 0));
    margin: 0 -15px;
    padding: 0 15px;
    .top {
      display: flex;
      padding-top: 50px;
      align-items: center;
      .van-image {
        width: 70px;
        height: 70px;
      }
      .name {
        padding-left: 10px;
        p {
          &:first-child {
            font-size: 18px;
            font-weight: 500;
          }
          &:last-child {
            margin-top: 10px;
            color: var(--cp-primary);
            font-size: 16px;
          }
        }
      }
    }
    .van-row {
      margin: 0 -15px;
      padding-top: 15px;
      p {
        text-align: center;
        &:first-child {
          font-size: 18px;
          font-weight: 500;
        }
        &:last-child {
          color: var(--cp-dark);
          font-size: 12px;
          padding-top: 4px;
        }
      }
    }
  }
  // 订单
  &-order {
    background-color: #fff;
    border-radius: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    .head {
      display: flex;
      justify-content: space-between;
      line-height: 50px;
      padding: 0 15px;
      a {
        color: var(--cp-tip);
      }
    }
    .van-col {
      
      text-align: center;
      .cp-icon {
        font-size: 28px;
      }
      p {
        font-size: 12px;
        padding-top: 4px;
      }
      
    }
  }
  // 分组
  &-group {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    h3 {
      padding-left: 16px;
      line-height: 44px;
    }
    .van-row {
      margin: 0 -15px;
      padding-top: 15px;
      p {
        text-align: center;
        &:first-child {
          font-size: 18px;
          font-weight: 500;
        }
        &:last-child {
          color: var(--cp-dark);
          font-size: 12px;
          padding-top: 4px;
        }
      }
      .van-col{
        text-align: center;
      .cp-icon {
        font-size: 28px;
      }
      p {
        font-size: 12px;
        padding-top: 4px;
      }
      }
    }
    .cp-icon {
      font-size: 17px;
      margin-right: 10px;
    }
  }
  .logout {
    display: block;
    margin: 20px auto;
    width: 100px;
    text-align: center;
    color: var(--cp-price);
  }
}
</style>
